package xyz.luhui1hao.rxjava2andretrofit2.api.http;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;

public class ApiMethods {

    /**
     * 封装线程管理和订阅的过程
     */
    public static void apiSubscribe(Observable observable, Observer observer) {
        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     *
     *
     * @param observer 由调用者传过来的观察者对象
     */
    public static void baseUrlRequest(Observer<ResponseBody> observer) {
        apiSubscribe(Api.getApiService().baseUrlRequest(), observer);
    }


    public static void doubanRequest(Observer<ResponseBody> observer, int start, int count){
        apiSubscribe(Api.getApiService().doubanRequest(start, count), observer);
    }

    public static void doubanRequestGet(Observer<ResponseBody> observer, int start, int count){
        apiSubscribe(Api.getApiService().doubanRequestGet(start, count), observer);
    }

}
